//
// Created by 45512 on 2021/11/10.
//
#include <iostream>

using namespace std;

int main() {
    int n;
    cin >> n;
    int B[n];
    for (int i = 0; i < n; i++) {
        cin >> B[i];
    }
    int sum_max = B[0];
    int sum_min = B[0];
    for (int i = 1; i < n; i++) {
        if (B[i] == B[i - 1]) {
            sum_max += B[i];
        } else if (B[i] > B[i - 1]) {
            sum_max += B[i];
            sum_min += B[i];
        }
    }
    cout << sum_max << endl;
    cout << sum_min << endl;
    return 0;


}